﻿<Window x:Class="ContactTracing.ExportView.ExportWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:local="clr-namespace:ContactTracing.ExportView"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        SizeToContent="WidthAndHeight"
        ResizeMode="NoResize"
        MinWidth="400"
        Title="Sync File Exporter (64-bit)">
    <Window.Resources>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

        <Color x:Key="MediumLightTextColor" A="255"     R="133 " G ="133"  B="135 "/>
        <Color x:Key="LightTextColor" A="255"           R="244 " G ="244 " B="248 "/>
        <Color x:Key="HighlightColor" A="255" R="0" G ="90" B="157"/>
        <Color x:Key="DarkTextColor" A="255"            R="51 "  G ="51 "  B="53"/>
        <Color x:Key="MediumTextColor" A="255"          R="98 "  G ="98 "  B="100 "/>

        <LinearGradientBrush x:Key="LightBackgroundBrush" StartPoint="1,0" EndPoint="1,1">
            <GradientStop Color="#EFF1F3" Offset="0" />
            <GradientStop Color="White" Offset="0.6" />
        </LinearGradientBrush>

        <SolidColorBrush x:Key="DarkTextBrush" Color="{StaticResource DarkTextColor}" />
        <SolidColorBrush x:Key="MediumTextBrush" Color="{StaticResource MediumTextColor}" />
        <SolidColorBrush x:Key="MediumLightTextBrush" Color="{StaticResource MediumLightTextColor}" />
        <SolidColorBrush x:Key="LightTextBrush" Color="{StaticResource LightTextColor}" />
        <SolidColorBrush x:Key="AccentBrush" Color="{StaticResource HighlightColor}" />

        <x:Array x:Key="RecordProcessingScopeListString" Type="local:ComboBoxItemString">
            <local:ComboBoxItemString ValueString="Active" DisplayString="Active records only" />
            <local:ComboBoxItemString ValueString="Deleted" DisplayString="Deleted records only" />
            <local:ComboBoxItemString ValueString="Both" DisplayString="Both active and deleted records" />
        </x:Array>

        <x:Array x:Key="DaysListString" Type="local:ComboBoxItemString">
            <local:ComboBoxItemString ValueString="1" DisplayString="1 day ago" />
            <local:ComboBoxItemString ValueString="2" DisplayString="2 days ago" />
            <local:ComboBoxItemString ValueString="3" DisplayString="3 days ago" />
            <local:ComboBoxItemString ValueString="4" DisplayString="4 days ago" />
            <local:ComboBoxItemString ValueString="5" DisplayString="5 days ago" />
            <local:ComboBoxItemString ValueString="6" DisplayString="6 days ago" />
            <local:ComboBoxItemString ValueString="7" DisplayString="7 days ago" />
            <local:ComboBoxItemString ValueString="8" DisplayString="8 days ago" />
            <local:ComboBoxItemString ValueString="9" DisplayString="9 days ago" />
            <local:ComboBoxItemString ValueString="10" DisplayString="10 days ago" />
            <local:ComboBoxItemString ValueString="11" DisplayString="11 days ago" />
            <local:ComboBoxItemString ValueString="12" DisplayString="12 days ago" />
            <local:ComboBoxItemString ValueString="13" DisplayString="13 days ago" />
            <local:ComboBoxItemString ValueString="14" DisplayString="14 days ago" />
            <local:ComboBoxItemString ValueString="18250" DisplayString="since the beginning" />
        </x:Array>

        <Style TargetType="Button">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <!--<Setter Property="Background" Value="{StaticResource DefaultButtonBrush}" />-->
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0" Color="#F0F0F4" />
                        <GradientStop Offset="1" Color="#E6E6EA" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="BorderBrush" Value="#BBBBBB" />
            <Setter Property="Foreground" Value="{StaticResource DarkTextBrush}" />
            <!--<Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="Foreground" Value="White" />-->
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border 
                        x:Name="BorderOuter"
                        BorderBrush="#EFEFEF"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        >
                            <Border x:Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    Background="{TemplateBinding Background}" 
                    Padding="{TemplateBinding Padding}" 
                    CornerRadius="0">
                                <ContentControl VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}" />
                            </Border>
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Background" TargetName="PART_Border" 
                                Value="Transparent"/>
                                <Setter Property="Foreground" 
                                Value="{StaticResource MediumTextBrush}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{StaticResource AccentBrush}" />
                    <Setter Property="Foreground" Value="{StaticResource LightTextBrush}" />
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter Property="Background" Value="{StaticResource AccentBrush}" />
                    <Setter Property="Foreground" Value="{StaticResource LightTextBrush}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        
        <!--<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/ContactTracing.WPF;component/Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>-->
    </Window.Resources>
    <Window.TaskbarItemInfo>
        <TaskbarItemInfo ProgressState="{Binding TaskbarProgressState}" ProgressValue="{Binding TaskbarProgressValue}" />
    </Window.TaskbarItemInfo>
    <Grid>
        <Border Background="{StaticResource LightBackgroundBrush}"
            Padding="20">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <StackPanel>
                    <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1">
                        <Rectangle HorizontalAlignment="Left" Width="100" Height="6" Fill="{StaticResource AccentBrush}" />
                        <TextBlock FontSize="24" Foreground="#444444" FontWeight="Bold" Text="DATA EXPORT OPTIONS" IsHitTestVisible="False" />
                    </StackPanel>

                    <StackPanel Height="14" />

                    <TextBlock Grid.Row="0" Grid.Column="1" Text="VHF project file:" />
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBox x:Name="tboxProjectFileName" Width="550" IsEnabled="False" Padding="2" Margin="0, 0, 10, 0" Text="{Binding ProjectFilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <Button x:Name="btnProjectBrowse" Grid.Column="1" VerticalAlignment="Stretch" Height="Auto" Content="Browse" Click="btnProjectBrowse_Click" />
                    </Grid>

                    <StackPanel Height="14" />

                    <TextBlock Grid.Row="0" Grid.Column="1" Text="Sync file:" />
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBox x:Name="tboxFileName" Width="550" IsEnabled="False" Padding="2" Margin="0, 0, 10, 0" Text="{Binding SyncFilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <Button x:Name="btnBrowse" Grid.Column="1" VerticalAlignment="Stretch" Height="Auto" Content="Browse" Click="btnBrowse_Click" />
                    </Grid>

                    <StackPanel Height="14" />

                    <RadioButton x:Name="includeCasesContacts" GroupName="N1" Content="Include case and contact data" IsChecked="{Binding IncludeCasesAndContacts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <StackPanel Height="4" />
                    <RadioButton x:Name="includeCasesOnly" GroupName="N1"  Content="Include case data only" IsChecked="{Binding IncludeCasesOnly, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <!--<StackPanel Height="4" />
                    <RadioButton x:Name="includeContactsOnly" GroupName="N1" Content="Include contact data only" />-->

                    <StackPanel Height="18" />

                    <!--<CheckBox Content="Filter data" IsChecked="False" x:Name="checkboxFilterData" Unchecked="checkboxFilterData_Unchecked" />
                    <StackPanel Height="4" />
                    <Grid IsEnabled="{Binding ElementName=checkboxFilterData, Path=IsChecked}" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Row="0" Grid.Column="1" Text="Case Variable" />

                        <ComboBox x:Name="cmbVariableName1" Width="120" Grid.Row="1" Grid.Column="1" Margin="0, 0, 4, 0">
                            <ComboBoxItem Content="DistrictRes" />
                            <ComboBoxItem Content="DistrictOnset" />
                            <ComboBoxItem Content="SCRes" />
                            <ComboBoxItem Content="SCOnset" />
                            <ComboBoxItem Content="ID" />
                        </ComboBox>
                        <ComboBox x:Name="cmbOperator1" Width="120" Grid.Row="1" Grid.Column="2" SelectedIndex="0" Margin="0, 0, 4, 0">
                            <ComboBoxItem Content="equals" />
                            <ComboBoxItem Content="contains" />
                        </ComboBox>
                        <TextBox x:Name="tboxValue1"  Width="120" Grid.Row="1" Grid.Column="3" Margin="0, 0, 0, 0" />

                        <ComboBox x:Name="cmbLogicalOperator" Grid.Row="2" Grid.Column="0" Margin="0, 4, 4, 0" SelectedIndex="0" Width="50">
                            <ComboBoxItem Content="" />
                            <ComboBoxItem Content="and" />
                            <ComboBoxItem Content="or" />
                        </ComboBox>

                        <ComboBox x:Name="cmbVariableName2" Width="120" Grid.Row="2" Grid.Column="1" Margin="0, 4, 4, 0" IsEnabled="{Binding ElementName=cmbLogicalOperator, Path=SelectedIndex, Converter={StaticResource CountToEnabledConverter}}">
                            <ComboBoxItem Content="DistrictRes" />
                            <ComboBoxItem Content="DistrictOnset" />
                            <ComboBoxItem Content="SCRes" />
                            <ComboBoxItem Content="SCOnset" />
                            <ComboBoxItem Content="ID" />
                        </ComboBox>
                        <ComboBox x:Name="cmbOperator2" Width="120" Grid.Row="2" Grid.Column="2" SelectedIndex="0" Margin="0, 4, 4, 0"  IsEnabled="{Binding ElementName=cmbLogicalOperator, Path=SelectedIndex, Converter={StaticResource CountToEnabledConverter}}">
                            <ComboBoxItem Content="equals" />
                            <ComboBoxItem Content="contains" />
                        </ComboBox>
                        <TextBox x:Name="tboxValue2"  Width="120" Grid.Row="2" Grid.Column="3" Margin="0, 4, 0, 0"  IsEnabled="{Binding ElementName=cmbLogicalOperator, Path=SelectedIndex, Converter={StaticResource CountToEnabledConverter}}" />
                    </Grid>-->

                    <!--<StackPanel Height="18" />-->

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Create differential sync file of case and contact records last updated between now and " Margin="0, 0, 4, 0" />
                        <ComboBox 
                                  HorizontalAlignment="Left" 
                                  SelectedIndex="13" 
                                  SelectedValue="{Binding Days, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                  ItemsSource="{StaticResource DaysListString}"
                                  DisplayMemberPath="DisplayString"
                                  SelectedValuePath="ValueString"/>
                    </StackPanel>
                    
                    <StackPanel Height="18" />

                    <CheckBox Content="De-identify data" x:Name="checkboxDeidentifyData" IsChecked="{Binding DeIdentifyData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                    <StackPanel Height="18" />

                    <TextBlock>Record processing scope:</TextBlock>
                    <ComboBox x:Name="cmbRecordProcessingScope" 
                              Width="200" 
                              HorizontalAlignment="Left" 
                              SelectedIndex="0" 
                              SelectedValue="{Binding RecordScope, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              ItemsSource="{StaticResource RecordProcessingScopeListString}" 
                              DisplayMemberPath="DisplayString"
                              SelectedValuePath="ValueString">
                        <!--<ComboBoxItem>Active records only</ComboBoxItem>
                        <ComboBoxItem>Deleted records only</ComboBoxItem>
                        <ComboBoxItem>Both active and deleted records</ComboBoxItem>-->
                    </ComboBox>

                </StackPanel>

                <UniformGrid Grid.Row="1" VerticalAlignment="Bottom" Rows="1" Columns="4" Width="Auto" Height="28" Margin="0, 15, 0, 0" HorizontalAlignment="Stretch">
                    <TextBlock Grid.Row="0" Grid.Column="0"></TextBlock>
                    <TextBlock Grid.Row="0" Grid.Column="1"></TextBlock>
                    <Button HorizontalAlignment="Stretch" 
                            Width="Auto" 
                            Grid.Row="0" 
                            Grid.Column="2" 
                            Margin="0, 0, 5, 0" 
                            x:Name="btnOK" 
                            Command="{Binding StartExportCommand}"
                            Click="btnOK_Click" 
                            Content="Export"/>
                    <Button HorizontalAlignment="Stretch" Width="Auto" Grid.Row="0" Grid.Column="3" Margin="5, 0, 0, 0" x:Name="btnCancel" Click="btnCancel_Click" Content="Close"/>
                </UniformGrid>
            </Grid>
        </Border>

        <DockPanel Grid.RowSpan="100" Background="#66000000" x:Name="panelDataExport" Visibility="{Binding IsShowingExportProgress, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" >
            <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <Border BorderBrush="{StaticResource AccentBrush}" BorderThickness="1" Background="{StaticResource LightBackgroundBrush}">
                    <StackPanel Margin="40, 20, 40, 20">

                        <StackPanel>
                            <Rectangle HorizontalAlignment="Left" Width="100" Height="6" Fill="{StaticResource AccentBrush}" />
                            <TextBlock FontSize="24" Foreground="#444444" FontWeight="Bold" Text="EXPORTING DATA" />
                        </StackPanel>

                        <StackPanel Height="10" />
                        <ProgressBar Width="520" HorizontalAlignment="Stretch" Height="16" Foreground="#558FFF" Minimum="0" Maximum="1" Value="{Binding ProgressValue, FallbackValue=0}" />
                        <StackPanel Height="4" />
                        
                        <TextBlock TextWrapping="Wrap" Text="{Binding SyncStatus, FallbackValue=...}" />
                        <StackPanel Height="6" />

                        <ProgressBar Width="520" HorizontalAlignment="Stretch" Height="16" Foreground="#558FFF" Minimum="0" Maximum="1" Value="{Binding TaskbarProgressValue, FallbackValue=0}" />
                        <StackPanel Height="4" />

                        <TextBlock TextWrapping="Wrap" Text="{Binding OverallSyncStatus, FallbackValue=...}" />
                        <TextBlock TextWrapping="Wrap" Text="{Binding RecordsExported, FallbackValue=...}" />
                        <StackPanel Height="4" />


                        <Button Width="90" Margin="4, 4, 0, 0" 
                                HorizontalAlignment="Right"
                                x:Name="panelDataExportOKButton" 
                                Command="{Binding StopExportCommand}"
                                Content="OK" />
                    </StackPanel>
                </Border>
            </DockPanel>
        </DockPanel>
    </Grid>
</Window>
